import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

let routes = [
  {
    path: '/',
    redirect: '/home/index'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login'),
  },
  {
    path: '/home',
    name: "home",
    component: HomeView,
    children: [

      {
        path: "index",
        component: () => import("../views/index/Index.vue"),
        meta: {
          thumb: ["首页"],
        },
      },
      {
        path: "driverschool-list",
        component: () => import("../views/driverschool/DriverSchoolList.vue"),
        meta: {
          thumb: ["驾校管理", "驾校列表"]
        },
      },
      {
        path: "driverschool-add",
        component: () => import("../views/driverschool/DriverSchoolAdd.vue"),
        meta: {
          thumb: ["驾校管理", "添加驾校"]
        },
      },
      {
        path: "driverschool-update/:id",
        component: () => import("../views/driverschool/DriverSchoolupdate.vue"),
        meta: {
          thumb: ["驾校管理", "修改驾校"],
        },
      },
      {
        path: "coach-list",
        component: () => import("../views/coach/CoachList.vue"),
        meta: {
          thumb: ["教练管理", "教练列表"],
        },
      },
      {
        path: "coach-add",
        component: () => import("../views/coach/CoachAdd.vue"),
        meta: {
          thumb: ["教练管理", "添加教练"],
        },
      },
      {
        path: "coach-update/:id",
        component: () => import("../views/coach/CoachUpdate.vue"),
        meta: {
          thumb: ["教练管理", "修改教练"],
        },
      },
      {
        path: "user-list",
        component: () => import("../views/user/UserList.vue"),
        meta: {
          thumb: ["用户管理", "用户列表"]
        },
      },
      {
        path: "user-add",
        component: () => import("../views/user/UserAdd.vue"),
        meta: {
          thumb: ["用户管理", "添加用户"]
        },
      },
      {
        path: "user-update/:id",
        component: () => import("../views/user/UserUpdate.vue"),
        meta: {
          thumb: ["用户管理", "修改用户"]
        },
      },
      {
        path: "exercises-list",
        component: () => import("../views/exercises/ExercisesList.vue"),
        meta: {
          thumb: ["习题管理", "习题列表"]
        },
      },
      {
        path: "exercises-add",
        component: () => import("../views/exercises/ExercisesAdd.vue"),
        meta: {
          thumb: ["习题管理", "添加习题"]
        },
      },
      {
        path: "exercises-update/:id",
        component: () => import("../views/exercises/ExercisesUpdate.vue"),
        meta: {
          thumb: ["习题管理", "修改习题"]
        },
      },
      {
        path: "information-list",
        component: () => import("../views/information/InformationList.vue"),
        meta: {
          thumb: ["资讯管理", "资讯列表"]
        },
      },
      {
        path: "admin-list",
        component: () => import("../views/admin/AdminList.vue"),
        meta: {
          thumb: ["管理员管理", "管理员列表"]
        },
      },
      {
        path: "admin-add",
        component: () => import("../views/admin/AdminAdd.vue"),
        meta: {
          thumb: ["管理员管理", "管理员用户"]
        },
      },
      {
        path: "admin-update/:id",
        component: () => import("../views/admin/AdminUpdate.vue"),
        meta: {
          thumb: ["管理员管理", "管理员修改"]
        },
      },
      {
        path: "information-add",
        component: () => import("../views/information/InformationAdd.vue"),
        meta: {
          thumb: ["资讯管理", "新增资讯"]
        },
      },
      {
        path: "information-update/:id",
        component: () => import("../views/information/InformationUpdate.vue"),
        meta: {
          thumb: ["资讯管理", "修改资讯"]
        },
      },

      // {
      //   path: "carousel-list",
      //   component: () => import("../views/carousel/CarouselList.vue"),
      //   meta: {
      //     thumb: ["轮播图管理", "轮播图列表"]
      //   },
      // },
      // {
      //   path: "carousel-add",
      //   component: () => import("../views/carousel/carouselAdd.vue"),
      //   meta: {
      //     thumb: ["轮播图管理", "轮播图增加"]
      //   },
      // },
      // {
      //   path: "carousel-update/:id",
      //   component: () => import("../views/carousel/CarouselList.vue"),
      //   meta: {
      //     thumb: ["管理员管理", "管理员修改"]
      //   },
      // },
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//添加全局前置守卫
import store from '@/store'
router.beforeEach((to, from, next) => {
  console.log(to)
  if (to.path == '/login' || store.state.user_name) {
    next()  // 继续下一步
  } else {
    router.push('/login')
  }
})

export default router
